﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;

using Model_Layer;

namespace Data_Access_Layer
{
    public class DBAirplane : IDBAirplane
    {
        private SqlConnection con;

        public DBAirplane()
        {
            con = Connection.GetInstance().GetConnection();
        }


        public Airplane getSpecificAirplane(int idairplane)
        {
            SqlDataReader reader = null;
            Airplane airplaneObj = null;
            string query = "SELECT * FROM Airplane WHERE idairplane = " + "'" + idairplane + "'";

            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(query, con);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    airplaneObj = new Airplane(int.Parse(reader["idairplane"].ToString()), int.Parse(reader["capacity"].ToString()),
                        reader["model"].ToString());
                }
               
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return airplaneObj;
        }
    }
}
